package com.firefly.admin.common.controller;

import com.firefly.admin.common.service.CommonService;
import com.firefly.admin.common.service.FtpService;
import com.firefly.admin.common.vo.ProvinceInfo;
import com.firefly.admin.common.vo.Result;
import com.firefly.admin.common.vo.Weather;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "公共接口API")
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private FtpService ftpService;
    @Autowired
    private CommonService commonService;

    /**
     * 公共文件上传接口
     *
     * @param file 文件信息
     * @return 上传结果
     */
    @ApiOperation(value = "公共文件上传接口", notes = "公共文件上传接口", httpMethod = "POST")
    @PostMapping("/upload")
    @CrossOrigin
    public Result<String> uploadFile(@RequestPart("file") MultipartFile file) {
        return ftpService.uploadFile(file);
    }

    /**
     * 获取天气信息接口
     *
     * @return 天气信息
     */
    @ApiOperation(value = "获取天气信息接口", notes = "获取天气信息接口", httpMethod = "GET")
    @GetMapping("/weather")
    public Result<Weather> getWeather() {
        return commonService.getWeather();
    }

    /**
     * 获取省份信息列表接口
     *
     * @return 省份信息列表
     */
    @ApiOperation(value = "获取省份信息列表接口", notes = "获取省份信息列表接口", httpMethod = "GET")
    @GetMapping("/province/list")
    public Result<List<ProvinceInfo>> getProvinceInfoList() {
        return commonService.getProvinceInfoList();
    }


}
